package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.ForeUserMapper;
import com.fc.test.model.auto.ForeUser;
import com.fc.test.model.auto.ForeUserExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 用户 ForeUserService
 * @Title: ForeUserService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 115889198@qq.com
 * @date 2020-09-02 20:27:30  
 **/
@Service
public class ForeUserService implements BaseService<ForeUser, ForeUserExample>{
	@Autowired
	private ForeUserMapper foreUserMapper;
	
      	   	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ForeUser> list(Tablepar tablepar,ForeUser record){
	        ForeUserExample testExample=new ForeUserExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andLikeQuery(record);
	        }
			//表格排序
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }else{
	        	testExample.setOrderByClause("id ASC");
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ForeUser> list= foreUserMapper.selectByExample(testExample);
	        PageInfo<ForeUser> pageInfo = new PageInfo<ForeUser>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=ConvertUtil.toListStrArray(ids);
			ForeUserExample example=new ForeUserExample();
			example.createCriteria().andIdIn(lista);
			return foreUserMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ForeUser selectByPrimaryKey(String id) {
				
			return foreUserMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ForeUser record) {
		return foreUserMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ForeUser record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return foreUserMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ForeUser record, ForeUserExample example) {
		
		return foreUserMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ForeUser record, ForeUserExample example) {
		
		return foreUserMapper.updateByExample(record, example);
	}

	@Override
	public List<ForeUser> selectByExample(ForeUserExample example) {
		
		return foreUserMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ForeUserExample example) {
		
		return foreUserMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ForeUserExample example) {
		
		return foreUserMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param foreUser
	 * @return
	 */
	public int checkNameUnique(ForeUser foreUser){
		ForeUserExample example=new ForeUserExample();
		example.createCriteria().andUsernameEqualTo(foreUser.getUsername());
		List<ForeUser> list=foreUserMapper.selectByExample(example);
		return list.size();
	}


}
